home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Comm / term-source.lha / Extras / Source / term-Source.lha / PrintPanel.c < prev    next >
C/C++ Source or Header  |  1995-06-17  |  7KB  |  310 lines

  1. /*
  2. **    PrintPanel.c
  3. **
  4. **    Control panel to set options for phonebook printing
  5. **
  6. **    Copyright © 1990-1995 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12. enum    {    GAD_FILE=1, GAD_PLAIN, GAD_USE, GAD_CANCEL, GAD_OPTION };
  13.  
  14. STATIC UBYTE __far    OutputFile[MAX_FILENAME_LENGTH] = "PRT:";
  15. STATIC ULONG        Flags = PRINT_SERIAL | PRINT_MODEM | PRINT_SCREEN | PRINT_TERMINAL | PRINT_USERNAME | PRINT_COMMENT;
  16. STATIC BYTE        Plain = FALSE;
  17.  
  18. VOID __regargs
  19. PrintPanel(struct Window *Window,struct List *PhoneList,LONG Count)
  20. {
  21.     struct LayoutHandle    *Handle;
  22.     BYTE             Result = FALSE;
  23.  
  24.     if(Handle = LT_CreateHandleTags(Window -> WScreen,
  25.         LH_LocaleHook,    &LocaleHook,
  26.     TAG_DONE))
  27.     {
  28.         struct Window    *PanelWindow;
  29.         UBYTE         Storage[6];
  30.  
  31.         LT_New(Handle,
  32.             LA_Type,    VERTICAL_KIND,
  33.         TAG_DONE);
  34.         {
  35.             LT_New(Handle,
  36.                 LA_Type,    HORIZONTAL_KIND,
  37.                 LA_LabelID,    MSG_V36_0152,
  38.             TAG_DONE);
  39.             {
  40.                 LT_New(Handle,
  41.                     LA_Type,    VERTICAL_KIND,
  42.                 TAG_DONE);
  43.                 {
  44.                     LONG i;
  45.  
  46.                     for(i = 0 ; i < 6 ; i++)
  47.                     {
  48.                         if(i == 3)
  49.                         {
  50.                             LT_EndGroup(Handle);
  51.  
  52.                             LT_New(Handle,
  53.                                 LA_Type,VERTICAL_KIND,
  54.                             TAG_DONE);
  55.                         }
  56.  
  57.                         if(Flags & (1L << i))
  58.                             Storage[i] = TRUE;
  59.                         else
  60.                             Storage[i] = FALSE;
  61.  
  62.                         LT_New(Handle,
  63.                             LA_Type,    CHECKBOX_KIND,
  64.                             LA_LabelID,    MSG_PRINTPANEL_INCLUDE_SERIAL_GAD + i,
  65.                             LA_ID,        GAD_OPTION + i,
  66.                             LA_BYTE,    &Storage[i],
  67.                         TAG_DONE);
  68.                     }
  69.  
  70.                     LT_EndGroup(Handle);
  71.                 }
  72.  
  73.                 LT_EndGroup(Handle);
  74.             }
  75.  
  76.             LT_New(Handle,
  77.                 LA_Type,    VERTICAL_KIND,
  78.                 LA_LabelID,    MSG_V36_0153,
  79.             TAG_DONE);
  80.             {
  81.                 LT_New(Handle,
  82.                     LA_Type,    STRING_KIND,
  83.                     LA_LabelID,    MSG_PRINTPANEL_OUTPUT_FILE_OR_DEVICE_GAD,
  84.                     LA_ID,        GAD_FILE,
  85.                     LA_STRPTR,    OutputFile,
  86.                     LA_Chars,    30,
  87.                     LAST_Picker,    TRUE,
  88.                     GTST_MaxChars,    MAX_FILENAME_LENGTH - 1,
  89.                 TAG_DONE);
  90.  
  91.                 LT_New(Handle,
  92.                     LA_Type,    CHECKBOX_KIND,
  93.                     LA_LabelID,    MSG_PRINTPANEL_PLAIN_TEXT_GAD,
  94.                     LA_ID,        GAD_PLAIN,
  95.                     LA_BYTE,    &Plain,
  96.                 TAG_DONE);
  97.  
  98.                 LT_EndGroup(Handle);
  99.             }
  100.  
  101.             LT_New(Handle,
  102.                 LA_Type,VERTICAL_KIND,
  103.             TAG_DONE);
  104.             {
  105.                 LT_New(Handle,
  106.                     LA_Type,    XBAR_KIND,
  107.                     LAXB_FullSize,    TRUE,
  108.                 TAG_DONE);
  109.  
  110.                 LT_EndGroup(Handle);
  111.             }
  112.  
  113.             LT_New(Handle,LA_Type,HORIZONTAL_KIND,
  114.                 LAGR_SameSize,    TRUE,
  115.                 LAGR_Spread,    TRUE,
  116.             TAG_DONE);
  117.             {
  118.                 LT_New(Handle,
  119.                     LA_Type,    BUTTON_KIND,
  120.                     LA_LabelID,    MSG_GLOBAL_USE_GAD,
  121.                     LA_ID,        GAD_USE,
  122.                     LABT_ReturnKey,    TRUE,
  123.                     LABT_ExtraFat,    TRUE,
  124.                 TAG_DONE);
  125.  
  126.                 LT_New(Handle,
  127.                     LA_Type,    BUTTON_KIND,
  128.                     LA_LabelID,    MSG_GLOBAL_CANCEL_GAD,
  129.                     LA_ID,        GAD_CANCEL,
  130.                     LABT_EscKey,    TRUE,
  131.                     LABT_ExtraFat,    TRUE,
  132.                 TAG_DONE);
  133.  
  134.                 LT_EndGroup(Handle);
  135.             }
  136.  
  137.             LT_EndGroup(Handle);
  138.         }
  139.  
  140.         if(PanelWindow = LT_Layout(Handle,LocaleString(MSG_PRINTPANEL_OUTPUT_OPTIONS_TXT),NULL,0,0,IDCMP_CLOSEWINDOW,0,
  141.             LAWN_HelpHook,        &GuideHook,
  142.             LAWN_Parent,        Window,
  143.             WA_DepthGadget,        TRUE,
  144.             WA_CloseGadget,        TRUE,
  145.             WA_DragBar,        TRUE,
  146.             WA_RMBTrap,        TRUE,
  147.             WA_Activate,        TRUE,
  148.         TAG_DONE))
  149.         {
  150.             struct IntuiMessage    *Message;
  151.             BOOLEAN             Done = FALSE;
  152.             ULONG             MsgClass,
  153.                          MsgQualifier;
  154.             UWORD             MsgCode;
  155.             struct Gadget        *MsgGadget;
  156.  
  157.             GuideContext(CONTEXT_PRINT);
  158.  
  159.             PushWindow(PanelWindow);
  160.  
  161.             do
  162.             {
  163.                 if(Wait(PORTMASK(PanelWindow -> UserPort) | SIG_BREAK) & SIG_BREAK)
  164.                     break;
  165.  
  166.                 while(Message = (struct IntuiMessage *)GT_GetIMsg(PanelWindow -> UserPort))
  167.                 {
  168.                     MsgClass    = Message -> Class;
  169.                     MsgQualifier    = Message -> Qualifier;
  170.                     MsgCode        = Message -> Code;
  171.                     MsgGadget    = (struct Gadget *)Message -> IAddress;
  172.  
  173.                     GT_ReplyIMsg(Message);
  174.  
  175.                     LT_HandleInput(Handle,MsgQualifier,&MsgClass,&MsgCode,&MsgGadget);
  176.  
  177.                     if(MsgClass == IDCMP_CLOSEWINDOW)
  178.                         Done = TRUE;
  179.  
  180.                     if(MsgClass == IDCMP_IDCMPUPDATE && MsgGadget -> GadgetID == GAD_FILE)
  181.                     {
  182.                         UBYTE             DummyBuffer[MAX_FILENAME_LENGTH],
  183.                                     *DummyChar;
  184.                         struct FileRequester    *FileRequest;
  185.  
  186.                         LT_LockWindow(PanelWindow);
  187.  
  188.                         SplitFileName(OutputFile,&DummyChar,DummyBuffer);
  189.  
  190.                         if(!DummyChar[0])
  191.                         {
  192.                             DummyBuffer[0] = 0;
  193.  
  194.                             DummyChar = LocaleString(MSG_PRINTPANEL_FILENAME_TXT);
  195.                         }
  196.  
  197.                         if(FileRequest = GetFile(PanelWindow,LocaleString(MSG_PRINTPANEL_SELECT_OUTPUT_FILE_TXT),DummyBuffer,DummyChar,DummyBuffer,NULL,FALSE,FALSE,FALSE,LocaleString(MSG_GLOBAL_SELECT_TXT),TRUE))
  198.                         {
  199.                             LT_SetAttributes(Handle,GAD_FILE,
  200.                                 GTST_String,DummyBuffer,
  201.                             TAG_DONE);
  202.  
  203.                             FreeAslRequest(FileRequest);
  204.                         }
  205.  
  206.                         LT_UnlockWindow(PanelWindow);
  207.                     }
  208.  
  209.                     if(MsgClass == IDCMP_GADGETUP)
  210.                     {
  211.                         LONG i;
  212.  
  213.                         switch(MsgGadget -> GadgetID)
  214.                         {
  215.                             case GAD_USE:
  216.  
  217.                                 LT_UpdateStrings(Handle);
  218.  
  219.                                 Flags = NULL;
  220.  
  221.                                 for(i = 0 ; i < 6 ; i++)
  222.                                 {
  223.                                     if(Storage[i])
  224.                                         Flags |= (1L << i);
  225.                                 }
  226.  
  227.                                 Result = Done = TRUE;
  228.                                 break;
  229.  
  230.                             case GAD_CANCEL:
  231.  
  232.                                 Done = TRUE;
  233.                                 break;
  234.                         }
  235.                     }
  236.                 }
  237.             }
  238.             while(!Done);
  239.  
  240.             PopWindow();
  241.         }
  242.  
  243.         LT_DeleteHandle(Handle);
  244.     }
  245.  
  246.     if(Result)
  247.     {
  248.         LONG Error = 0;
  249.         BPTR File;
  250.  
  251.         if(File = Open(OutputFile,MODE_NEWFILE))
  252.         {
  253.             struct Window        *ReqWindow;
  254.             struct EasyStruct     Easy;
  255.  
  256.             Easy . es_StructSize    = sizeof(struct EasyStruct);
  257.             Easy . es_Flags        = NULL;
  258.             Easy . es_Title        = (UBYTE *)LocaleString(MSG_TERMAUX_TERM_REQUEST_TXT);
  259.             Easy . es_GadgetFormat    = (UBYTE *)LocaleString(MSG_PRINT_STOP_TXT);
  260.             Easy . es_TextFormat    = (UBYTE *)LocaleString(MSG_PRINT_PRINTING_PHONEBOOK_TXT);
  261.  
  262.             if(ReqWindow = BuildEasyRequest(Window,&Easy,NULL))
  263.             {
  264.                 struct PhoneNode    *TempNode;
  265.                 BYTE             Continue = TRUE;
  266.  
  267.                 if(Count > 0)
  268.                 {
  269.                     for(TempNode = (struct PhoneNode *)PhoneList -> lh_Head ; Continue && TempNode -> VanillaNode . ln_Succ ; TempNode = (struct PhoneNode *)TempNode -> VanillaNode . ln_Succ)
  270.                     {
  271.                         if(TempNode -> Entry -> Count >= 0)
  272.                             Continue = PrintEntry(File,ReqWindow,Plain,&Error,TempNode -> Entry,Flags);
  273.                     }
  274.                 }
  275.                 else
  276.                 {
  277.                     for(TempNode = (struct PhoneNode *)PhoneList -> lh_Head ; Continue && TempNode -> VanillaNode . ln_Succ ; TempNode = (struct PhoneNode *)TempNode -> VanillaNode . ln_Succ)
  278.                         Continue = PrintEntry(File,ReqWindow,Plain,&Error,TempNode -> Entry,Flags);
  279.                 }
  280.  
  281.                 FreeSysRequest(ReqWindow);
  282.             }
  283.  
  284.             Close(File);
  285.  
  286.             if(PathPart(OutputFile) != OutputFile)
  287.             {
  288.                 AddProtection(OutputFile,FIBF_EXECUTE);
  289.  
  290.                 if(Config -> MiscConfig -> CreateIcons)
  291.                     AddIcon(OutputFile,FILETYPE_TEXT,TRUE);
  292.             }
  293.         }
  294.         else
  295.             Error = IoErr();
  296.  
  297.         if(Error)
  298.         {
  299.             STRPTR ErrorString;
  300.  
  301.             if(Fault(Error,"",SharedBuffer,MAX_FILENAME_LENGTH))
  302.                 ErrorString = SharedBuffer;
  303.             else
  304.                 ErrorString = "???";
  305.  
  306.             MyEasyRequest(Window,LocaleString(MSG_PRINT_ERROR_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),Error,ErrorString);
  307.         }
  308.     }
  309. }
  310.